// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({
    env: cloud.DYNAMIC_CURRENT_ENV
})
const db = cloud.database()
const _ = db.command
// 云函数入口函数
exports.main = async (event, context) => {
    const {id} = event
    const article = await db.collection('article').where({
        _id:_.eq(id)
    }).get()
    const {attachments} = article.data[0]
    const result = await db.collection('article').where({
        _id:_.eq(id)
    }).remove()
    const delImgResult = await cloud.deleteFile({
        fileList:attachments
    })
    return {
        result
    }
}